<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let obj = {
            friend: {
                name: "罗佰君"
            },
            name: ""
        }

        // 左侧如果为null或者undefined取右侧值，否则取左侧值
        let friend = obj.friend ?? "没有";
        console.log("friend = ",friend)

        let girlFriendName = obj.girlFriend ?? "没有";
        console.log("girlFriendName = ",girlFriendName)


        let name = obj.name || "匿名";
        console.log("ES5.name = ",name);

        name = obj.name ?? "匿名"; // "匿名"
        console.log("ES5.name = ",name); // ""
    </script>


</body>
</html>